<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
header('Content-Type: text/xml; charset=UTF-8');

$daytime = strtotime(date('Y-m-d'));
$condition = array( 
		"begin_time <= {$daytime}",
		"end_time > {$daytime}",
		);

/* city filter----
$ename = strval($_GET['ename']);
if ($ename && $ename!='none') {
	$city = DB::LimitQuery('category', array(
		'condition' => array(
			'zone' => 'city',
			'ename' => $ename,
		),
		'one' => true,
	));
}
if ($ename||$city) $condition['city_id'] = abs(intval($city['id']));
---- end city filter */

$teams = DB::LimitQuery('team', array(
			'condition' => $condition,
			'order' => 'ORDER BY sort_order DESC, id DESC',
			'size' => $pagesize,
			'offset' => $offset,
			));

$oa = array();
$si = array(
		'sitename' => $INI['system']['sitename'],
		'wwwprefix' => $INI['system']['wwwprefix'],
		'imgprefix' => $INI['system']['imgprefix'],
		);

foreach($teams AS $one) {
	$city = Table::Fetch('category', $one['city_id']);
	$group = Table::Fetch('category', $one['group_id']);
	$partner = Table::Fetch('partner', $one['partner_id']);
	$item = array();
	$item['loc'] = $si['wwwprefix'] . "/team.php?id={$one['id']}";
	$item['data'] = array();
	$item['data']['website'] = array();
	$t=array();
	$t['sitename']=$INI['system']['sitename'];
	$t['siteurl']= $INI['system']['wwwprefix'];
	($t['city'] = $city['name']) || ($t['city'] = '全国');
	$item['data']['display'] = array();

	$o = array();
	$class=$group['name'];
	if($group['name']=='生活服务'){
		$class='美容保健';
	}else if($group['name']=='旅游酒店'){
		$class='其他团购';
	}else if($group['name']=='网上购物'){
		$class='精品网购';
	}else if($group['name']=='化妆品'){
		$class='精品网购';
	}
	$o['identifier'] = '114';
	$o['title'] = $one['title'];
	$o['smallimage'] = team_image($one['image'], true);
	$o['image'] = $si['imgprefix']  .'/static/' . $one['image'];
	$o['tag'] = $class;
	$o['startTime'] = $one['begin_time'];
	$o['endTime'] = $one['end_time'];
	$o['value'] = $one['market_price'];
	$o['price'] = $one['team_price'];
	$o['bought']=abs(intval($one['now_number']));
	//$o['detail']=$one['detail'];
	$x=array();
	$p = Table::Fetch('partner', $one['partner_id']);
	$x['name']= $p['title'];
	$x['tel'] = $p['phone'];
	$x['addr']=$p['address'];
	$item['data']['display'] = $o;
	$item['data']['website'] = $t;
    $item['data']['shops']['shop'] = $x;
	$oa[] = $item;
}

Output::XmlBaidu($oa);
